package thomas.javase.string;

import org.junit.Test;

public class StringFormatTest {

    @Test
    public void testStringFormat1(){
        String target1 = "abc%sefghij%sk";
        String result = String.format(target1, "1", "2");
        System.out.println(result);
    }

    @Test
    public void testStringFormat2(){
        int nextPageNumber = 2;
        String result = String.format("//a[@class='changePage' and text()='%d']", nextPageNumber);
        System.out.println(result);
    }

    @Test
    public void testContain(){
        String str = "Dialogue: 0,0:02:30.69,0:02:31.91,*Default,NTP,0000,0000,0000,,装船\\N{\\fn方正综艺简体}{\\fs14}{\\b0}{\\c&HFFFFFF&}{\\3c&H2F2F2F&}{\\4c&H000000&}Load it up.";
        String strStart = "{\\4c&H000000&}";
        if(str.contains(strStart)){
            System.out.println("contained");
        }
    }

    @Test
    public void testContain2(){
        String str = "<html><head></head><body><h1>Nginx forbidden.</h1> <br>request info: 218.19.24.171";
        String strStart = "Nginx forbidden.";
        if(str.contains(strStart)){
            System.out.println("contained");
        }
    }

    @Test
    public void testSubstring1(){
        System.out.println("------------");
        System.out.println(this.getGnCodeFromUrl("http://q.10jqka.com.cn/gn/detail/code/301121/"));

    }
    public String getGnCodeFromUrl(String gnUrl){
        String result = null;
        if(gnUrl != null){
            String[] array = gnUrl.split("/");
            result = array[array.length-1];
        }
        return result;
    }

}
